//
//  SXViewController.m
//  SXDataManager
//
//  Created by wangshuixin on 01/05/2019.
//  Copyright (c) 2019 wangshuixin. All rights reserved.
//

#import "SXViewController.h"
#import "SXDataManager-umbrella.h"
#import "SXSingletonClass.h"
#import "SXThreeViewController.h"

@interface SXViewController ()

@end

@implementation SXViewController

#pragma mark - Lifecycle
- (instancetype)init {
    if (self = [super init]) {
        self = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateInitialViewController];
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"导航栏";
	// Do any additional setup after loading the view, typically from a nib.
    [self exampleForUsingSXDataCheckManager];
    [self exampleForUsingSXDataConvertManager];
    NSLog(@"jquery文件:%@", [SXGetBundleData dataPathForResource:@"SX_jquery.js" ofType:nil]);
    NSLog(@"图片：%@", [SXGetBundleData SXImageName:@"filter"]);
    NSDictionary *temp = @{@"key1":@"value1", @"key2":@"value2", @"key3":@[@"1", @"2", @"3"], @"key4":@[@{@"key3":@[@"1", @"2", @"3"]},@{@"key3":@[@{@"key3":@[@"1", @"2", @"3"]}, @"2", @"3"]}], @"key5":@"value5"};
    NSLog(@"字典所有keys：%@ , %lu", temp.allKeys, (unsigned long)temp.allKeys.count);
    if ([temp isKindOfClass:[NSDictionary class]]) {
        NSArray *arr = [self getDictionaryData:temp];
        NSLog(@"子元素中所有数组元素：%@", arr);
    }
    [SXSingletonClass sharedSXSingletonClass];
    NSLog(@"当前模式Debug：%d", [SXDataManager currentBuildConfigurationEqualsDebug]);
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [SXSystemNavigationSetting dismissDynamicTitleViewOnNavigationItem:self.navigationItem];
}
- (void)viewWillAppear:(BOOL)animated {
    [SXSingletonClass sharedSXSingletonClass];
    [self performSelector:@selector(customNaviAnimation) withObject:nil afterDelay:0.5];
}
- (void)customNaviAnimation {
    [SXSystemNavigationSetting settingForDynamicTitleViewOnNavigationItem:self.navigationItem message:@"test"];
    // 建立socket连接
    SXBSDSocketManager *socket = [SXBSDSocketManager shareInstance];
    [socket connectToHost:@"192.168.1.4" port:@9090];
}

- (void)viewDidAppear:(BOOL)animated {
    [SXSingletonClass sharedSXSingletonClass];
}

- (NSArray *)getDictionaryData:(NSDictionary *)temp {
    NSMutableArray *tagArray = [NSMutableArray array];
    for (int i = 0; i < temp.allValues.count; i ++) {
        if ([temp.allValues[i] isKindOfClass:[NSArray class]]) {
            [tagArray addObject:temp.allValues[i]];
        }
    }
    return tagArray;
}

#pragma mark - Private Methods
- (void)exampleForUsingSXDataCheckManager {
    NSLog(@"========== 数据校验 start ==========");
    NSLog(@"汉字判定(%@)，结果：%d", @"汉字", [SXDataCheckManager checkChineseFromCharacter:@"汉字"]);
    NSLog(@"汉字判定(%@)，结果：%d", @"china", [SXDataCheckManager checkChineseFromCharacter:@"china"]);
    NSLog(@"汉字判定(%@)，结果：%d", @"汉字Chinese", [SXDataCheckManager checkChineseFromCharacter:@"汉字Chinese"]);
    NSLog(@"邮件判定(%@)，结果：%d", @"2412658453@mail.com", [SXDataCheckManager checkNormalEmailFormatFromString:@"2412658453@mail.com"]);
    NSLog(@"邮件判定(%@)，结果：%d", @"邮件@mail.com", [SXDataCheckManager checkNormalEmailFormatFromString:@"邮件@mail.com"]);
    NSLog(@"邮件判定(%@)，结果：%d", @"check.mail.com", [SXDataCheckManager checkNormalEmailFormatFromString:@"check.mail.com"]);
    NSLog(@"========== 数据校验 end ==========\n\n\n");
}

- (void)exampleForUsingSXDataConvertManager {
    NSLog(@"========== 数据转换 start ==========");
    NSLog(@"NSDictionary转jsonString(%@)，转换后：%@", @{@"key":@"value"}, [SXDataConvertManager convertToJsonStringFromNSDictionary:@{@"key":@"value"}]);
    NSString *jsonString = [SXDataConvertManager convertToJsonStringFromNSDictionary:@{@"key":@"value"}];
    NSLog(@"jsonString 转 NSDictionary(%@)， 转换后：%@", jsonString, [SXDataConvertManager convertToNSDictionaryFromJsonString:jsonString]);
    NSLog(@"汉字转Pinyin(%@)， 转换后：%@", @"汉字", [SXDataConvertManager convertToPinyinFromChineseCharacters:@"汉字"]);
    NSLog(@"汉字转Pinyin(%@)， 转换后：%@", @"汉字有声调", [SXDataConvertManager convertToPinyinToneFromChineseCharacters:@"汉字有声调"]);
    NSLog(@"获取汉字首字母(%@)，转换后：%@", @"汉字首字母Chinese", [SXDataConvertManager getPinYinPrefixLetterFromChineseCharacters:@"汉字首字母Chinese"]);
    NSLog(@"时间戳转标准时间(%d)，转换后：%@", 1546776569, [SXDataConvertManager convertToStandardTimeFromTimestamp:@"1546776569"]);
    NSLog(@"标准时间转时间戳(%@)，转换后：%@", @"2019-01-01 15:44:56", [SXDataConvertManager convertToTimestampFromStandardTime:@"2019-01-01 15:44:56"]);
    NSLog(@"图片NSData转UIImage转换：%@", [SXDataConvertManager convertToImageFromData:UIImagePNGRepresentation([SXGetBundleData SXImageName:@"filter"])]);
    NSLog(@"图片UIImage转NSData转换：%@", [SXDataConvertManager convertToDataFromImage:[SXGetBundleData SXImageName:@"filter"]]);
    self.view.backgroundColor = [SXDataConvertManager convertToColorFromHexString:@"#87CEFA"];
    NSLog(@"========== 数据转换 end ==========\n\n\n");
}

#pragma mark - Xib Action Events
- (IBAction)skipOneVC:(UIButton *)sender {
    [SXRouter openURL:@"mgj://detail?id=404"];
}

- (IBAction)skipTwoVC:(UIButton *)sender {
    [self callSocket];
}

- (IBAction)skipThreeVC:(UIButton *)sender {
//    [SXRouter openURL:@"mgj://detail" withUserInfo:nil completion:^(id  _Nonnull result) {
////        [self appendLog:@"Open 结束，我是 Completion Block"];
//        NSLog(@"result:%@",result);
//    }];
    
    [SXRouter openURL:[SXRouter generateURLWithPattern:@"mgj://search/:keyword" parameters:@[@"Hangzhou"]]];
}

- (void)callSocket {
    SXBSDSocketManager *socket = [SXBSDSocketManager shareInstance];
    [socket sendMessage:@"测试一下连接服务器！"];
    socket.returnStateInformation = ^(NSString * _Nonnull stateInformation) {
        NSLog(@"返回的信息：%@", stateInformation);
    };
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
